<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改信息</title>
    <link href="../css/Own_Mes_Amend.css" rel="stylesheet" />
    <script src="../js/jquery-2.1.1.min.js"></script>
    <script src="../js/jquery-3.4.1.min.js"></script>
</head>
<body>
<div id="containner">
    <div id="content1">
        <div id="left1">
            <img id="head">
        </div>
        <div id="middle1">
            <div id="banner1"><input type="text" class="input1" id="UserName" value=""></div>
            <div id="footer1"><input type="text" class="input2" id="ID" value=""></div>
        </div>
        <div id="right1">
            <input type="button" class="input0" onclick="confirm1()" value="确定">
        </div>
    </div>
    <div id="content2">
        <div id="content3">
            <div id="left2">
                <div class="banner"><input type="text" class="input3" id="Sno" value=""></div>
                <div class="footer"><input type="text" class="input3" id="QQ" value=""></div>
            </div>
            <div id="middle2">
                <div class="banner"><input type="text" class="input3" id="Sex" value=""></div>
                <div class="footer"><input type="text" class="input3" id="Phone" value=""></div>
            </div>
            <div id="footer2">
                <p>个性签名：</p>
                <textarea class="input4" id="Intro"></textarea>
            </div>
        </div>
        <div id="right2">
            <input type="button" class="input0" onclick="confirm2()" value="确定">
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function ()
        {
            // var Mes = localStorage.getItem("HeadMes");              //localStorage
            // sessionStorage.removeItem("head_message");              //localStorage
            // sessionStorage.setItem("head_message", Mes);            //localStorage
            var message = JSON.parse(sessionStorage.getItem("head_message"));

            var UserName = message.username;
            document.getElementById('UserName').placeholder = UserName;
            var ID = "ID："+message.Uid;
            document.getElementById('ID').value = ID;
            var HeadImg = message.headimg;
            var Sno = "学号："+message.name;
            document.getElementById('Sno').placeholder = Sno;
            var Sex = "性别："+message.sex;
            document.getElementById('Sex').placeholder = Sex;
            var QQ = "Q Q："+message.QQ;
            document.getElementById('QQ').placeholder = QQ;
            var Phone = "手机号："+message.phone;
            document.getElementById('Phone').placeholder = Phone;
            var Intro = message.intro;

            var str1 = "<img src=\"../img/user_img/"+ HeadImg+"\" id=\"head\">";
            var str2 = ""+Intro;
            $("#left1").empty();
            $("#left1").html(str1);
            $("#Intro").html(str2);

            var change = document.getElementById('head');
            change.onmouseover = function() {
                change.src="../img/Own_img/Own_Mes_Amend.png";
            }
            change.onmouseout = function() {
                change.src="../img/user_img/"+HeadImg;
            }
        })


        function confirm1() {
            var message = JSON.parse(sessionStorage.getItem("head_message"));
            var UserName = document.getElementById('UserName').value;
            if (UserName!=null){ message.username = UserName;}
            var map = JSON.stringify(message);
            // localStorage.removeItem("HeadMes");
            // localStorage.setItem("HeadMes", map);
            sessionStorage.removeItem("head_message");
            sessionStorage.setItem("head_message", map);

            var par = {"username":message.username, "Uid":message.Uid};
            $.post("/amend1", par, function (result) {
                if (result == true)
                {
                    alert("呢称修改成功");
                    location.reload();
                }else
                {
                    alert("修改失败");
                }
            })
        }

        function confirm2() {
            var message = JSON.parse(sessionStorage.getItem("head_message"));
            var Sno = document.getElementById('Sno').value;
            if (Sno!=""){message.name = Sno;}
            var Sex = document.getElementById('Sex').value;
            if (Sex!=""){message.sex = Sex;}
            var QQ = document.getElementById('QQ').value;
            if (QQ!=""){message.QQ = QQ;}
            var Phone = document.getElementById('Phone').value;
            if (Phone!=""){message.phone = Phone;}
            var Intro = document.getElementById('Intro').value;
            if (Intro!=""){message.intro = Intro;}
            var map = JSON.stringify(message);
            // localStorage.removeItem("HeadMes");
            // localStorage.setItem("HeadMes", map);
            sessionStorage.removeItem("head_message");
            sessionStorage.setItem("head_message", map);

            var par = {"Uid":message.Uid, "sno":message.name, "phone":message.phone, "sex":message.sex, "QQ":message.QQ, "intro":message.intro};
            $.post("/amend2", par, function (result) {
                if (result == true)
                {
                    alert("信息修改成功");
                    location.reload();
                }else
                {
                    alert("修改失败");
                }
            })
        }
    </script>

</div>
</body>
</html>